package org.jeecg.modules.app.shopmember.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.ApiLogin;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.app.shopmember.service.AppShopDetailsService;
import org.jeecg.modules.power.order.entity.YlPowerBankOrder;
import org.jeecg.modules.power.order.service.IYlPowerBankOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

/**
 * @BelongsProject: jeecg-boot-parent
 * @BelongsPackage: org.jeecg.modules.app.shopmember.controller
 * @Author: mi
 * @CreateTime: 2024-08-13 09:15
 * @Description:
 */
@CrossOrigin
@Api(tags = "APP运营端-门店详情相关接口")
@RestController
@RequestMapping("/api/appShopDetails")
public class AppShopDetails {


    @Autowired
    private  AppShopDetailsService appShopDetailsService;

    @Autowired
    private IYlPowerBankOrderService ylPowerBankOrderService;//订单


    //门店详情 -进入统计模块-数据


    //获取门店会员类行  getShopMemberTypeList    今日  昨日 近7天 本月
    @ApiLogin
    @ApiOperation(value = "门店详情-进入统计模块-数据", notes = "门店详情 -进入统计模块-数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "店铺id", required = true),
            @ApiImplicitParam(name = "type", value = "1 今日  2昨日 3近7天 4本月", required = true),
    })
    @GetMapping("/getShopIdData")
    public Result<?> getShopIdData(HttpServletRequest request, String id,Integer type){
        if (oConvertUtils.isEmpty(id))return Result.error_599("店铺id不可为空");
        if (oConvertUtils.isEmpty(type))type=1;

        return appShopDetailsService.getShopIdData(id, type);
    }

    //折线图   getShopIdDataLineChart
    @ApiLogin
    @ApiOperation(value = "门店详情-进入统计模块-数据", notes = "门店详情 -进入统计模块-数据图-折线图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "店铺id", required = true),
            @ApiImplicitParam(name = "type", value = "1 近30天  2 近6个月", required = true),
    })
    @GetMapping("/getShopIdDataLineChart")
    public Result<?> getShopIdDataLineChart(HttpServletRequest request, String id,Integer type)throws ParseException {
        if (oConvertUtils.isEmpty(id))return Result.error_599("店铺id不可为空");
        if (oConvertUtils.isEmpty(type))type=1;
        return appShopDetailsService.getShopIdDataLineChart(id, type);
    }

    //订单  getShopIdOrder
    @ApiLogin
    @ApiOperation(value = "门店详情-统计模块-订单", notes = "门店详情 -进入统计模块-订单列表 分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "店铺id", required = true),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "数量", required = true),
    })
    @GetMapping("/getShopIdOrderList")
    public Result<List<YlPowerBankOrder>> getShopIdOrderList(HttpServletRequest request, String id,
                                    @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                    @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
        Page<YlPowerBankOrder> page = new Page<YlPowerBankOrder>(pageNo, pageSize);
        QueryWrapper<YlPowerBankOrder> queryWrapper =new QueryWrapper<YlPowerBankOrder>();
        queryWrapper.eq("lease_shop_id",id);
        queryWrapper.orderByDesc("create_time");
        IPage<YlPowerBankOrder> pageList = ylPowerBankOrderService.page(page, queryWrapper);
        Result< List<YlPowerBankOrder>> result = new Result< List<YlPowerBankOrder>>();
        result.setCode(200);
        result.setResult(pageList.getRecords());
        return result;

    }






    @ApiLogin
    @ApiOperation(value = "门店详情-统计模块-订单详情", notes = "门店详情 -进入统计模块-订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true),
    })
    @GetMapping("/getShopIdOrderDetails")
    public Result<?> getShopIdOrderDetails(HttpServletRequest request, String id){
        YlPowerBankOrder powerBankOrder= ylPowerBankOrderService.getById(id);
        if (oConvertUtils.isEmpty(powerBankOrder))return Result.error_599("订单数据错误");
        return Result.OK(powerBankOrder);
    }




}
